package com.lighting.smssystem.configuration;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lighting.smssystem.model.User;
import com.lighting.smssystem.utils.JWTUtils;
import com.lighting.smssystem.utils.ResponseUtil;
import com.lighting.smssystem.utils.ThreadContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;

/**
 * Author LeeMaster
 *
 * for jwt authentication
 */
@Configuration
@ConditionalOnProperty(prefix = "system",name = "auth",havingValue = "true")
public class JWTFilterConfiguration {

    private static ObjectMapper objectMapper = new ObjectMapper();

    public static String[] white = {
            ""
    };

    /**
     * 鉴权filter
     * @return
     */
    @Bean
    public FilterRegistrationBean<AuthFilter> authFiler(){
        FilterRegistrationBean<AuthFilter> bean = new FilterRegistrationBean<>();

        System.out.println("12312");
        bean.setFilter(
                new AuthFilter()
        );

        bean.setOrder(100);

        bean.setUrlPatterns(Arrays.asList(
                "/**"
        ));



        return bean;
    }


}
